package cn.cxyxj.study01;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author cxyxj
 */
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    PasswordEncoder passwordEncoder() {
       // return NoOpPasswordEncoder.getInstance();
        return new BCryptPasswordEncoder();
    }

   @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("cxyxj")
                .password( passwordEncoder().encode("123")).roles("admin","user")
                .and()
                .withUser("security")
                .password("security").roles("user");

      //  auth.userDetailsService(userDetailsService());
    }

 /*   @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/hello").hasRole("admin")
                .anyRequest().authenticated()
                ;
    }
*/
   /*@Bean
    @Override
    protected UserDetailsService userDetailsService() {
        return username -> new User("cxyxj", "12345",
                AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }*/


}
